package com.cims.bpm.security.advice.encrypt;

import com.cims.bpm.config.CimsConfigProperties;
import com.cims.bpm.security.advice.Decrypt;
import com.cims.bpm.security.utils.security.Constants;
import com.cims.bpm.security.utils.sm4.Sm4Utils;
import org.apache.xerces.impl.dv.util.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

/**
 * SM4加密
 */
@Component
public class Sm4Encrypt implements Decrypt {

    @Autowired
    CimsConfigProperties cimsConfigProperties;

    @Override
    public String execute(String body) {
        byte[] sm4Key = cimsConfigProperties.getSecurity().getSm4Key().getBytes();
        String result = Base64.encode(Sm4Utils.sm4EcbEncrypt(sm4Key, body.getBytes(), Constants.PAD_NO));
        return result;
    }
}
